﻿namespace PMS.Client
{
    using PMS.BLL;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Linq;
    using System.Windows.Forms;

    public class FrmError : Form
    {
        private Button button1;
        private IContainer components = null;

        public FrmError()
        {
            this.InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OrganBLL nbll = new OrganBLL();
            List<Organ> source = nbll.GetList();
            using (List<Organ>.Enumerator enumerator = source.GetEnumerator())
            {
                Func<Organ, bool> predicate = null;
                Organ item;
                while (enumerator.MoveNext())
                {
                    item = enumerator.Current;
                    if (item.OrganCode.IndexOf("-") > 0)
                    {
                        if (predicate == null)
                        {
                            predicate = f => f.OrganCode == item.OrganCode.Substring(0, item.OrganCode.LastIndexOf("-"));
                        }
                        Organ organ = source.FirstOrDefault<Organ>(predicate);
                        if (organ != null)
                        {
                            item.ParentID = new int?(organ.OrganID);
                            item.LevelNo = new int?(organ.OrganCode.ToArray<char>().ToList<char>().FindAll(f => f.ToString() == "-").Count + 1);
                            nbll.Update(item);
                        }
                    }
                }
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.button1 = new Button();
            base.SuspendLayout();
            this.button1.Location = new Point(0xb1, 0xb0);
            this.button1.Name = "button1";
            this.button1.Size = new Size(0x4b, 0x25);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new EventHandler(this.button1_Click);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x189, 0xe9);
            base.Controls.Add(this.button1);
            this.DoubleBuffered = true;
            base.Name = "FrmError";
            this.Text = "FrmError";
            base.ResumeLayout(false);
        }
    }
}

